home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
IRIX 6.5 Applications 1998 June
/
SGI IRIX 6.5 Applications 1998 June.iso
/
dist
/
arraysvcs.idb
/
usr
/
etc
/
arrayconfig.z
/
arrayconfig
Wrap
Text File
|
1998-04-15
|
4KB
|
172 lines
#!/bin/sh
#
# Array configuration script: sets up an arrayd.conf file with an initial
# array, then distributes it to all of the machines in the array and activates
# array services.
#
# Usage: arrayconfig [-a arrayname] [-i] [-m] [-d] host...
#
# Options:
# -a arrayname: name the array "arrayname"
# -i: Tune the kernel to use the bottom 15 bits of the current hostid
# as a permanent machine ID for global ASHs. With "-d", this is
# done on each machine in the array.
# -m: Make an arrayd.conf file
# -d: Distribute the arrayd.conf file across the array and activate
# array services
# host...: hostnames of one or more machines that make up the array
#
ConfigDir=/usr/lib/array
ConfigFile=$ConfigDir/arrayd.conf
Template=$ConfigDir/arrayd.conf.template
Usage="$0 [-a array] [-m] [-i] [-d] host..."
#
# Parse options
#
DoDist=0
DoMachID=0
DoMake=0
Array="default"
while getopts "a:dim" CurrOpt; do
case $CurrOpt in
a) Array=$OPTARG;;
d) DoDist=1;;
i) DoMachID=1;;
m) DoMake=1;;
*) echo $Usage
exit 2;
esac
done
shift `expr $OPTIND - 1`
#
# Check arguments for sensible-ness
#
if [ $# -lt 1 -a $DoMachID -eq 0 ]; then
echo "Must specify at least one host"
echo $Usage
exit 2
fi
Hosts=$*
if [ $DoMake -eq 0 -a $DoMachID -eq 0 -a $DoDist -eq 0 ]; then
echo "Must specify -d, -i or -m"
echo $Usage
exit 2
fi
#
# Make sure the appropriate directories and files exist and are writable
#
if [ ! -d $ConfigDir ]; then
echo "Error! Configuration directory $ConfigDir not found"
exit 2
fi
if [ ! -w $ConfigDir ]; then
echo "Error! Cannot write to $ConfigDir"
exit 2
fi
if [ ! -f $Template -a $DoMake -ne 0 ]; then
echo "Error! Configuration file template $Template not found"
exit 2;
fi
#
# Make the config file if desired
#
if [ $DoMake -ne 0 ]; then
#
# Make sure the configuration file is writable
#
if [ -f $ConfigFile ]; then
echo "Warning: configuration file $ConfigFile already exists"
if [ -w $ConfigFile ]; then
echo -n "Overwrite it? (y/n) "
read Answer
if [ "$Answer" != "y" ]; then
echo "$0 aborting"
exit 0;
fi
else
echo "Error! configuration file $ConfigFile is read-only"
exit 2;
fi
fi
#
# Generate a temporary filename
#
TempFile=$ConfigDir/arrayconfig.temporary.$$
if [ -f $TempFile ]; then
echo "Temporary file $TempFile already exists! Try again."
exit 2;
fi
#
# Create a temporary file containing the array definition
#
echo "array $Array" > $TempFile
for Host in $Hosts; do
echo " machine $Host" >> $TempFile
done
#
# Transmogrify the template file
#
sed -e "/#-AC1-/r $TempFile" \
-e "/#-AC1-/d" \
-e "/#-AC2-/s/.*/ destination array $Array/" \
-e "/#-AC3-/d" \
$Template > $ConfigFile
#
# Don't need the temporary file any longer
#
rm $TempFile
fi
#
# If we are setting a machine ID but *not* distributing configs,
# do the actual systune
#
if [ $DoMachID -ne 0 -a $DoDist -eq 0 ]; then
HostID=`hostid`
MachID=`perl -e "print $HostID & 0x7fff"`
echo "asmachid $MachID\ny\nquit" | systune -i > /dev/null 2>&1
fi
#
# Distribute the configuration file and activate it if desired
#
if [ $DoDist -ne 0 ]; then
for Host in $Hosts; do
rcp $ConfigFile $Host:$ConfigFile
rsh $Host /sbin/chkconfig array on
rsh $Host /etc/init.d/array stop
rsh $Host /etc/init.d/array start > /dev/null
if [ $DoMachID -ne 0 ]; then
rsh $Host /usr/etc/arrayconfig -i > /dev/null
fi
done
fi
#
# Print reboot reminder if necessary
#
if [ $DoMachID -ne 0 ]; then
echo "Reboot system to use new machine ID"
fi
echo "Configuration of array $Array complete"
exit 0